﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Castle.ActiveRecord;
using System.ComponentModel.DataAnnotations;
using Castle.ActiveRecord.Queries;
using NHibernate;

namespace ZDSoft.LMS.Domain
{
    /// <summary>
    /// 功能：调度
    /// 作者：方选正 
    /// 日期：2012年1月2日
    /// </summary>
    [ActiveRecord("DeliveryForm")]
    public class DeliveryForm : EntityBase
    {
        /// <summary>
        /// 运输时间
        /// </summary>
        [Property(NotNull = true, ColumnType = "DateTime")]
        [Display(Name = "运输时间")]
        [Required(ErrorMessage = "运输时间不能为空！")]
        public virtual DateTime DeliveryDate { get; set; }
    
        /// <summary>
        /// 运输卡车
        /// </summary>
        //[Required(ErrorMessage = "不能为空")]
        [BelongsTo("TransportCarID",Lazy= FetchWhen.OnInvoke)]
        public virtual Vehicle Vehicle { get; set; }

        /// <summary>
        /// 运输司机
        /// </summary>
        [BelongsTo("TransporterID",Lazy = FetchWhen.OnInvoke)]
        public virtual Driver Transporter { get; set; }

        /// <summary>
        /// 调度者
        /// </summary>
        [BelongsTo("CreatorID",Lazy = FetchWhen.OnInvoke)]
        public virtual User Creator { get; set; }

        /// <summary>
        /// 订单项目,1个订单项目可能包括一个送货单
        /// </summary>
        [BelongsTo("TranportOrderID",Lazy=FetchWhen.OnInvoke)]
        public virtual TransportOrder TransportOrder { get; set; }

        #region 辅助属性
        private int vehicleID;
        [Display(Name = "运输车辆")]
        [Required(ErrorMessage = "请选择运输车辆！")]
        public int VehicleID
        {
            get { if (Vehicle != null) { return Vehicle.ID; } return vehicleID; }
            set { vehicleID = value; }
        }

        private int transporterID;
        [Display(Name = "送货人员")]
        [Required(ErrorMessage = "请选择送货人员！")]
        public int TransporterID
        {
            get { if (Transporter != null) { return Transporter.ID; } return transporterID; }
            set { transporterID = value; }
        }
        #endregion
    }
}
